import os
import jaydebeapi
import yaml

url = 'jdbc:hive2://bigdata112.depts.bingosoft.net:22112/user08_db'
user = 'user08'
password = 'pass@bingo8'
dirver = 'org.apache.hive.jdbc.HiveDriver'




# sql = 'show tables'
sql='desc formatted t_rk_jbxx'

def get_jar():
    DIR = './tlib/'
    jarFile = []
    for i in os.listdir(DIR):
        jarFile.append(DIR+i)
    return jarFile


# jdbc连接
def connect():
    jarFile = get_jar()
    conn = jaydebeapi.connect(dirver, url, [user, password], jarFile)
    curs = conn.cursor()
    curs.execute(sql)
    result = curs.fetchall()
    print(result)
    curs.close()
    conn.close()

def read_yaml():
    with open('config.yaml') as f:
        config_data = yaml.load(f, Loader=yaml.FullLoader)
    print(config_data['password'])
    config_data['user']='user07'
    print(config_data)
    with open('config.yaml','w') as f:
        yaml.dump(config_data,f,Dumper=yaml.Dumper)


if __name__ == '__main__':
    connect()
    # read_yaml()
